import 'package:flutter/material.dart';

class CustomTabIndicator extends Decoration {
  CustomTabIndicator({
    this.width = 0.87,
    this.radius = 1,
    this.subLen = 4,
    this.color = Colors.black,
  });

  final double radius;

  final double width;

  final double subLen;

  final Color color;

  @override
  _UnderlinePainter createBoxPainter([VoidCallback? onChanged]) {
    return _UnderlinePainter(this, onChanged!);
  }
}

class _UnderlinePainter extends BoxPainter {
  final CustomTabIndicator? decoration;

  _UnderlinePainter(this.decoration, VoidCallback onChanged)
      : assert(decoration != null),
        super(onChanged);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration? configuration) {
    assert(configuration != null);
    assert(configuration!.size != null);

    final Rect rect = offset & configuration!.size!;

    final RRect newrRect = RRect.fromLTRBXY(
      rect.left + decoration!.subLen,
      rect.bottom * decoration!.width,
      rect.right - decoration!.subLen,
      rect.bottom - 4,
      decoration!.radius,
      decoration!.radius,
    );

    canvas.drawRRect(
      newrRect,
      Paint()
        ..style = PaintingStyle.fill
        ..color = decoration!.color,
    );
  }
}
